#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

long long countAlternatingSubarrays(vector<int>& nums) {
    int last = -1;
    long long res = 0;
    int l = 0, r = 0;
    while (r < nums.size())
    {
        if (last == -1)
            last = nums[r], res++;
        else
        {
            if (nums[r] != last) res += r - l + 1;
            else    l = r, res++;
            last = nums[r];
        }
        r++;
    }
    return res;
}